package Q506;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 相对名次
 *
 * @author 23737
 * @time 2021.12.2
 */
public class Test {
    public static void main(String[] args) {
        String[] relativeRanks = new Solution().findRelativeRanks(new int[]{10, 3, 8, 9, 4});
        for (String relativeRank : relativeRanks) {
            System.out.println(relativeRank);
        }
    }
}


class Solution {
    public String[] findRelativeRanks(int[] score) {
        //define
        Map<Integer, String> map = new HashMap<>();
        String[] res = new String[score.length];
        String[] value = new String[]{"Gold Medal", "Silver Medal", "Bronze Medal"};
        int[] ints = Arrays.copyOf(score, score.length);

        Arrays.sort(score);
        int[] scoreReverse = new int[score.length];
        for (int i = 0; i < score.length; i++) {
            scoreReverse[i] = score[score.length-1-i];
        }

        for (int i = 0; i < scoreReverse.length; i++) {
            if(i <= 2){
                map.put(scoreReverse[i], value[i]);
            }else {
                map.put(scoreReverse[i], String.valueOf(i+1));
            }
        }

        //result
        for (int i = 0; i < ints.length; i++) {
            res[i] = map.get(ints[i]);
        }
        return res;
    }
}
